$(document).ready(function () {
    getDepArray();
    $("#submit").click(function () {
        sub();
    })
})

function depAppand(data) {
    var array = data;
    var is="";
    for (var i = 0; i < array.length; i++) {
        is+="<li><a href=\"#\" onclick=\"hid(this,"+array[i].id +")\">"+array[i].name+"</a></li>";
    }
    $("#ul").empty()
    $("#ul").append(is);
}
function hid(obj,va){
    $("#departmentId").val(va);
    $( "#dt").html($(obj).html());
    $("#dd").hide();
}



function sub() {
    var name = $("#name").val();
    var password = $("#password").val();
    var phone = $("#phone").val();
    var departmentId = $("#departmentId").val();
    var userName=$("#userName").val();
    var sex=$("#sex").val();
    var inSchoolTime=$("#inSchoolTime").val();
    var startWorkTime=$("#startWorkTime").val();
    var direction=$("#direction").val();
    var role = window.location.search.substring(1);


    var data= "name="+name+"&password="+password+"&phone="+phone+"&departmentId="+departmentId
    +"&userName="+userName+"&sex="+sex+"&"+role+"&direction="+direction;
    if(inSchoolTime!=null && inSchoolTime!= ""){
        data+="&inSchool="+timeChange(inSchoolTime)
    }
    if(startWorkTime!=null && startWorkTime!= ""){
        data+="&startWork="+timeChange(startWorkTime)
    }
    var allUrl=url;
    if(role=="role=1"){
        allUrl+=studentAddUrl;
    }else{
        allUrl+=teacherAddUrl;
    }
    $.ajax({
        "url": allUrl,
        "type": 'post',
        "data": data,
        "dataType": "json",
        "success": function (data) {
            var res = eval('(' + JSON.stringify(data) + ')');
            if (res.resultCode != 200) {
                error(data);
                return;
            }
            alert("添加成功！")
            window.close();
        }
    })
}
function timeChange(strtime){
    // var strtime = '2014-04-23 18:55:49:123';
    var date = new Date(strtime); //传入一个时间格式，如果不传入就是获取现在的时间了，这样做不兼容火狐。
// 可以这样做
    var date = new Date(strtime.replace(/-/g, '/'));

// 有三种方式获取，在后面会讲到三种方式的区别
    time1 = date.getTime();
    // time2 = date.valueOf();
    // time3 = Date.parse(date);
    return time1
}

